package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class EventAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const EVENT_ATTEND:String        = "event.attend";
        public static const EVENT_GET_ATTENDEES:String = "event.getAttendees";
        public static const EVENT_GET_INFO:String      = "event.getInfo";
        public static const EVENT_GET_SHOUTS:String    = "event.getShouts";
        public static const EVENT_SHARE:String         = "event.share";
        public static const EVENT_SHOUT:String         = "event.shout";

        
        public function EventAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        

        /** event.attend */
        public function attend(onComplete:Function, 
                              onError:Function,
                              event:String,
                              status:int):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = EventAPI.EVENT_ATTEND;
            urlVars["event"]  = event;
            urlVars["status"] = status;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }  
        
        

        /** event.getAttendees */
        public function getAttendees(onComplete:Function, 
                              onError:Function,
                              event:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = EventAPI.EVENT_GET_ATTENDEES;
            urlVars["event"]  = event;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }  
        

        /** event.getInfo */
        public function getInfo(onComplete:Function, 
                              onError:Function,
                              event:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = EventAPI.EVENT_GET_INFO;
            urlVars["event"]  = event;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        } 
        

        /** event.getShouts */
        public function getShouts(onComplete:Function, 
                              onError:Function,
                              event:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = EventAPI.EVENT_GET_SHOUTS;
            urlVars["event"]  = event;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        } 
        

        /** event.share */
        public function share(onComplete:Function, 
                              onError:Function,
                              event:String,
                              recipient:String,
                              message:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = EventAPI.EVENT_SHARE;
            urlVars["event"]  = event;
            urlVars["recipient"]  = recipient;
            if (message!=null) urlVars["message"]  = message;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        } 
        

        /** event.shout */
        public function shout(onComplete:Function, 
                              onError:Function,
                              event:String,
                              message:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = EventAPI.EVENT_SHOUT;
            urlVars["event"]  = event;
            urlVars["message"]  = message;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        } 
    }
}